package com.ytktt.study.week4.task2;

import java.util.concurrent.locks.LockSupport;

/**
 * LockSupport方式
 *
 * @author ytk
 */
public class LockSupportDemo {

    private static volatile int result = 0;

    public static void main(String[] args) {
        Thread currentThread = Thread.currentThread();
        Thread t = new Thread(() -> {
            result = sum();
            LockSupport.unpark(currentThread);
        }, "LockSupport");
        t.start();
        LockSupport.park();
        System.out.println("异步计算结果为：" + result);
    }

    private static int sum() {
        return fibo(36);
    }

    private static int fibo(int a) {
        if (a < 2) {
            return 1;
        }
        return fibo(a - 1) + fibo(a - 2);
    }
}
